package edu.faytechcc.csc289.data;

import java.io.*;
import java.util.*;
import javax.swing.*;

/**
 * Class loads file for dynamic customization for taxes and systems
 * 
 * Apr 13, 2014
 *
 * @author William Robles
 */
public class FileLoader
{

    public FileLoader()
    {

    }

    /**
     * getFile method takes arraylist and populates with a chosen file
     * based on a string
     *
     * @param list ArrayList to populate
     * @param file string to decide what file to load
     */
    public void getFile(ArrayList list, String file)
    {
        String str = "";
        if (file.equals("systems"))
        {
            str = "res/systems.txt";
        }
        else if (file.equals("taxes"))
        {
            str = "res/taxes.txt";
        }
        
        try
        {
            Scanner reader = new Scanner(new File(str));

            String line;

            while (reader.hasNext())
            {
                line = reader.nextLine();
                if (!line.equals(""))
                {
                    line = line.trim();
                    if (!line.startsWith("#"))
                    {
                        list.add(line);
                    }
                }
            }

            reader.close();
        }
        catch (Exception e)
        {
            JOptionPane.showMessageDialog(null,
                    "NO FILE DETECTED");
        }
    }

}
